package com.example.hp.widgettest_321lz;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView tv;
    private EditText et;
    private Button btngettext, btnsettimg,button4 ,button5;
    private ImageButton ibtn;
    private ImageView iv;
    private RadioButton radioButtonnan, radioButtonnv;
    private CheckBox checkfootball,checkbasketball,checksswim;
    private RadioGroup rg;
    private String strfun="";



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        rg=(RadioGroup)findViewById(R.id.radiogroup);
        tv = (TextView) findViewById(R.id.textview);
        et = (EditText) findViewById(R.id.editText);
        btngettext = (Button) findViewById(R.id.button);
        btnsettimg = (Button) findViewById(R.id.button2);
        iv = (ImageView) findViewById(R.id.imageView2);
        ibtn = (ImageButton) findViewById(R.id.imageButton);
        radioButtonnv=(RadioButton)findViewById(R.id.radioButton2);
        radioButtonnan=(RadioButton)findViewById(R.id.radioButton);
        checkfootball=(CheckBox)findViewById(R.id.checkBox2);
        checksswim=(CheckBox)findViewById(R.id.checkBox);
        checkbasketball=(CheckBox)findViewById(R.id.checkBox3);

        btngettext.setOnClickListener(this);
        btnsettimg.setOnClickListener(this);
        ibtn.setOnClickListener(this);
        button4=(Button)findViewById(R.id.button4);
        button5=(Button)findViewById(R.id.button5);
        button4.setOnClickListener(this);
        button5.setOnClickListener(this);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId)
                {
                    case R.id.radioButton:
                        tv.setText("女");
                        break;
                    case R.id.radioButton2:
                        tv.setText("男");
                }
            }
        });
        checkbasketball.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="篮球+";
                else
                    strfun=strfun.replace("篮球+","");
                tv.setText(strfun);

            }
        });
        checkfootball.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="足球+";
                else
                    strfun=strfun.replace("足球+","");
                tv.setText(strfun);
            }
        });
        checksswim.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="游泳+";
                else
                    strfun=strfun.replace("游泳+","");
                tv.setText(strfun);
            }
        });



    }

    @Override
    public void onClick(View v) {
switch(v.getId()){
    case R.id.button:
        String str = et.getText().toString();
        tv.setText(str);
    case R.id.button2:
        iv.setImageResource(R.drawable.liuzheng1);
    case R.id.imageButton:
        Intent intent=new Intent(MainActivity.this,NewActivity.class);
        intent.putExtra("param1",et.getText().toString());
        intent.putExtra("param2",3);
        startActivity(intent);
    case R.id.button4:
        if(radioButtonnv.isChecked()) tv.setText("男");
        if(radioButtonnan.isChecked()) tv.setText("女");
        break;
    case R.id.button5:
        String msg="";
        if(checksswim.isChecked()) msg+="游泳+";
        if(checkfootball.isChecked()) msg+="足球+";
        if(checkbasketball.isChecked()) msg+="篮球+";
        tv.setText(msg);
        break;



}
    }
}


